﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMathLibrary.Management
{
    /// <summary>
    /// This class allows the building of object trees with objects of any type.
    /// </summary>
    /// <typeparam name="T">The type of the treenode.</typeparam>
    [Serializable]
    public class TreeNode<T>
    {
        /// <summary>
        /// The value of the treenode.
        /// </summary>
        private T value;

        /// <summary>
        /// The children of the treenode.
        /// </summary>
        private readonly List<TreeNode<T>> children;

        /// <summary>
        /// Initializes a new instance of the <see cref="TreeNode&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="value">The value of the treenode.</param>
        public TreeNode(T value)
        {
            this.value = value;
            this.children = new List<TreeNode<T>>();
        }

        /// <summary>
        /// Gets or sets the value of the treenode.
        /// </summary>
        /// <value>The value of the treenode.</value>
        public T Value
        {
            get { return value; }
            set { this.value = value; }
        }

        /// <summary>
        /// Gets the children of the current treenode.
        /// </summary>
        /// <value>The children of the current treenode.</value>
        public List<TreeNode<T>> Children
        {
            get { return children; }
        }

        /// <summary>
        /// Gets or sets the <see cref="SmartMathLibrary.Management.TreeNode&lt;T&gt;"/> at the specified index.
        /// </summary>
        /// <value>The <see cref="SmartMathLibrary.Management.TreeNode&lt;T&gt;"/> at the specified index.</value>
        public TreeNode<T> this[int index]
        {
            get { return this.children[index]; }
            set { this.children[index] = value; }
        }
    }
}